if(!window.js2se)window.js2se=window.java={};

java.text={};

java.text.Format=function(){
	this.format=function(){alert("java.text.Format.format is abstract method.")};
	this.parseObject=function(){alert("java.text.Format.parseObject is abstract method.")};
};

java.text.NumberFormat=function(){
	this.extend(java.text.Format);
	this.INTEGER_FIELD=0;
	this.FRACTION_FIELD=1;
	var parseIntegerOnly=false;
	this.isParseIntegerOnly=function(){return parseIntegerOnly};
	this.setParseIntegerOnly=function(value){parseIntegerOnly=value};
	this.parse=function(){alert("java.text.NumberFormat.parse is abstract method.")};
};
java.text.NumberFormat.INTEGER_FIELD=0;
java.text.NumberFormat.FRACTION_FIELD=1;

java.text.DateFormat=function(){
	this.extend(java.text.Format);
	var numberFormat;
	this.setNumberFormat=function(format){numberFormat=format};
	this.getNumberFormat=function(){return numberFormat};
	this.parse=function(){alert("java.text.DateFormat.parse is abstract method.")};
	
	var self=this;
	with(self){
		ERA_FIELD=0;YEAR_FIELD=1;MONTH_FIELD=2;DATE_FIELD=3;
		HOUR_OF_DAY1_FIELD=4;HOUR_OF_DAY0_FIELD=5;MINUTE_FIELD=6;
		SECOND_FIELD=7;MILLISECOND_FIELD=8;
		DAY_OF_WEEK_FIELD=9;DAY_OF_YEAR_FIELD=10;DAY_OF_WEEK_IN_MONTH_FIELD=11;
		WEEK_OF_YEAR_FIELD=12;WEEK_OF_MONTH_FIELD=13;
		AM_PM_FIELD=14;HOUR1_FIELD=15;HOUR0_FIELD=16;TIMEZONE_FIELD=17;
		FULL=0;LONG=1;MEDIUM=2;SHORT=3;DEFAULT=2;
	}
};
with(java.text.DateFormat){
	ERA_FIELD=0;YEAR_FIELD=1;MONTH_FIELD=2;DATE_FIELD=3;
	HOUR_OF_DAY1_FIELD=4;HOUR_OF_DAY0_FIELD=5;MINUTE_FIELD=6;
	SECOND_FIELD=7;MILLISECOND_FIELD=8;
	DAY_OF_WEEK_FIELD=9;DAY_OF_YEAR_FIELD=10;DAY_OF_WEEK_IN_MONTH_FIELD=11;
	WEEK_OF_YEAR_FIELD=12;WEEK_OF_MONTH_FIELD=13;
	AM_PM_FIELD=14;HOUR1_FIELD=15;HOUR0_FIELD=16;TIMEZONE_FIELD=17;
	FULL=0;LONG=1;MEDIUM=2;SHORT=3;DEFAULT=2;
}

java.text.ParseException=function(message,cause,type){return new Exception(message,cause,type||"java.text.ParseException")};

java.text.DateFormatSymbols=function(locale){
	if(!locale&&java.util&&java.util.Locale&&java.util.Locale.getDefault)locale=java.util.Locale.getDefault();
	var months=["January","February","March","April","May","June","July","August","September","October","November","December"];
	var shortMonths=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];
	var weekdays=["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"];
	var shortWeekdays=["Mon","Tue","Wed","Thu","Fri","Sat","Sun"];
	this.getMonths=function(){return months};
	this.setMonths=function(m){months=m};
	this.getShortMonths=function(){return shortMonths};
	this.setShortMonths=function(m){shortMonths=m};
	this.getWeekdays=function(){return weekdays};
	this.setWeekdays=function(d){weekdays=d};
	this.getShortWeekdays=function(){return shortWeekdays};
	this.setShortWeekdays=function(d){shortWeekdays=d};
	
	if(java.util&&java.util.ResourceBundle){
		rb=java.util.ResourceBundle.getBundle("locale",locale);
		var a=rb.getStringArray("months");if(a&&a.length)months=a;
		a=rb.getStringArray("short.months");if(a&&a.length)shortMonths=a;
		a=rb.getStringArray("day.names");if(a&&a.length)weekdays=a;
		a=rb.getStringArray("day.abbreviations");if(a&&a.length)shortWeekdays=a;
	}
};

java.text.SimpleDateFormat=function(pattern,formatSymbols){
	this.extend(java.text.DateFormat);
	var fs=formatSymbols||new java.text.DateFormatSymbols();
	var pt=pattern;

	this.getDateFormatSymbols=function(){return fs};
	this.setDateFormatSymbols=function(newFormatSymbols){if(!newFormatSymbols)throw new NullPointerException("SimpleDateFormat.setDateFormatSymbols(): the given newFormatSymbols is null.");fs=newFormatSymbols};
	this.toPattern=function(){return pt};
	this.applyPattern=function(pattern){var m,p=pattern;m="SimpleDateFormat.applyPattern(): the given pattern is ";if(p==null)throw new NullPointerException(m + "null.");if(!p)throw new IllegalArgumentException(m + "invalid.");pt=p};
	this.format=function format(date,toAppendTo){
		if(!toAppendTo)toAppendTo=new StringBuffer();
		var E,dd,M,y,H,h,m,s,p,r,d=date;
		if(!d)throw new NullPointerException("SimpleDateFormat.format(): the given date is null.");
		p=pt;E=d.getDay();
		if(ii(p,"EEEE"))E=fs.getWeekdays()[E-1];
		else if(ii(p,"EEE"))E=fs.getShortWeekdays()[E-1];
		else if(ii(p,"EE"))E=z(E);
		dd=d.getDate();dd=(ii(p,"dd")?z(dd):dd);
		m=d.getMonth();M=parseInt(m+1);M=(ii(p,"MM")?z(M):M);
		if(ii(p,"MMMM"))M=fs.getMonths()[m];
		else if(ii(p,"MMM"))M=fs.getShortMonths()[m];
		y=d.getFullYear();y=(ii(p,"yyyy")?z(y):(y.toString().substring(2,4)));
		h=d.getHours();h=(ii(p,"hh")?z(h):h);H=z(h);
		m=d.getMinutes();m=(ii(p,"mm")?z(m):m);
		s=d.getSeconds();s=(ii(p,"ss")?z(s):s);
		r=rr(p,/y{1,4}/g,y);r=rr(r,/h{1,2}/g,h);r= rr(r,/H{1,2}/g,H);r= rr(r,/m{1,2}/g,m);r= rr(r,/s{1,2}/g,s);
		r=rr(r,/d{1,2}/g,dd);r= rr(r,/E{1,4}/g,"%%%%%");r= rr(r,/M{1,4}/g,"#####");r= rr(r,/%%%%%/g,E);r= rr(r,/#####/g,M);
		return toAppendTo.append(r);
	};
	this.parse=function(source){
		var val=source+"";var p=pt+"";var i_val=0;var i_format=0;
		var c="";var t="";var t2="";var x,y;var now=new Date();
		var year=now.getYear();var month=now.getMonth()+1;var date=1;
		var hh="00";var mm="00";var ss="00";var ampm="";
		while(i_format<p.length){
			c=p.charAt(i_format);t="";
			while((p.charAt(i_format)==c)&&(i_format<p.length)){t+=p.charAt(i_format++)}
			if(t=="yyyy"||t=="yy"||t=="y"){
				if(t=="yyyy"){x=4;y=4}
				if(t=="yy"){x=2;y=2}
				if(t=="y"){x=2;y=4}
            	year=_getInt(val,i_val,x,y);
				if(year==null)throw new java.text.ParseException("Invalid year.("+val+")");
				i_val+=year.length;
				if(year.length==2)year=((year>70)?1900:2000)+(year-0)
			}else if(t=="MMM"||t=="MMMM"){
				MONTH_NAMES=fs.getMonths();
				MONTH_NAMES=MONTH_NAMES.concat(fs.getShortMonths());
				month=0;
				for(var i=0;i<MONTH_NAMES.length;i++){
					var month_name=MONTH_NAMES[i];
					if(val.substring(i_val,i_val+month_name.length).toLowerCase()==month_name.toLowerCase()){
						if(t=="MMM"||t=="MMMM"||(t=="MMMM"&&i>11)){month=i+1;if(month>12)month-=12;i_val += month_name.length;break}
					}
				}
				if((month < 1) ||(month > 12)) throw new java.text.ParseException("Invalid month.(" + val + ")");
			}else if(t=="EE"||t=="E"||t=="EEE"){
				DAY_NAMES=fs.getWeekdays();
				DAY_NAMES=DAY_NAMES.concat(fs.getShortWeekdays());
				for(var i=0;i<DAY_NAMES.length;i++){
					var day_name=DAY_NAMES[i];
					if(val.substring(i_val,i_val+day_name.length).toLowerCase()==day_name.toLowerCase()){i_val+=day_name.length;break}
				}
			}else if(t=="MM"||t=="M"){
				month=_getInt(val,i_val,t.length,2);
				if(month==null||(month<1)||(month>12))throw new java.text.ParseException("Invalid month.("+val+")");
				i_val+=month.length
			}else if(t=="dd"||t=="d"){
				date=_getInt(val,i_val,t.length,2);
				if(date==null||(date<1)||(date>31))throw new java.text.ParseException("Invalid date.("+val+")");
				i_val+=date.length
			}else if(t=="hh"||t=="h"){
				hh=_getInt(val,i_val,t.length,2);
				if(hh==null||(hh<0)||(hh>12))throw new java.text.ParseException("Invalid hours.("+val+")");
				i_val+=hh.length
			}else if(t=="HH"||t=="H"){
				hh=_getInt(val,i_val,t.length,2);
				if(hh==null||(hh<0)||(hh>23))throw new java.text.ParseException("Invalid hours.("+val+")");
				i_val+=hh.length
			}else if(t=="mm"||t=="m"){
				mm=_getInt(val,i_val,t.length,2);
				if(mm==null||(mm<0)||(mm>59))throw new java.text.ParseException("Invalid minutes.("+val+")");
				i_val+=mm.length
			}else if(t=="ss"||t=="s"){
				ss=_getInt(val,i_val,t.length,2);
				if(ss==null||(ss<0)||(ss>59))throw new java.text.ParseException("Invalid seconds.("+val+")");
				i_val+=ss.length
			}else if(t=="a"){
				if(val.substring(i_val,i_val+2).toLowerCase()=="am")ampm="AM";
				else if(val.substring(i_val,i_val+2).toLowerCase()=="pm")ampm="PM";
				else throw new java.text.ParseException("Invalid AM/PM.("+val+")");
				i_val+=2
			}else{
				if(val.substring(i_val,i_val+t.length)!= t)throw new java.text.ParseException("Invalid value.("+val+")");
				else i_val+=t.length
			}
		}
		if(i_val!= val.length)throw new java.text.ParseException("Invalid value.("+val+")");
		if(month==2){
			if(((year%4==0)&&(year%100!=0))||(year%400==0)){
				if(date>29)throw new java.text.ParseException("Invalid month.("+val+")");
			}else {if(date>28)throw new java.text.ParseException("Invalid date.("+val+")")}
		}
		if((month==4)||(month==6)||(month==9)||(month==11))if(date>30)throw new java.text.ParseException("Invalid date.("+val+")");
		if(hh<12&&ampm=="PM")hh=hh-0+12;
		else if(hh>11&&ampm=="AM")hh-=12;
		return new Date(year,month-1,date,hh,mm,ss)
	};
	function z(n){return((n<10)?"0":"")+n}
	function ii(s, S){return(s.indexOf(S)>-1)}
	function rr(s,p,r){return s.replace(p,r)}   
	function _isInteger(v){var i,d="1234567890";for(i=0;i<v.length;i++)if(d.indexOf(v.charAt(i))==-1)return false;return true}
	function _getInt(str, i, min, max){var t,x;for(x=max;x>=min;x--){t=str.substring(i,i+x);if(t.length<min)return null;if(_isInteger(t))return t}return null}
};
